home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / cluster.zip / WEAPONS.QC < prev   
Text File  |  1996-08-08  |  27KB  |  1,297 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");  // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");  // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav"); // player shotgun
  17.     precache_sound ("weapons/ric1.wav");  // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");  // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");  // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");  // super spikes
  21.     precache_sound ("weapons/tink1.wav"); // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav"); // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");    // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav"); // super shotgun
  25. };
  26.  
  27. float() crandom =
  28. {
  29.     return 2*(random() - 0.5);
  30. };
  31.  
  32. /*
  33. ================
  34. W_FireAxe
  35. ================
  36. */
  37. void() W_FireAxe =
  38. {
  39.     local vector  source;
  40.     local vector  org;
  41.  
  42.     source = self.origin + '0 0 16';
  43.     traceline (source, source + v_forward*64, FALSE, self);
  44.     if (trace_fraction == 1.0)
  45.         return;
  46.     
  47.     org = trace_endpos - v_forward*4;
  48.  
  49.     if (trace_ent.takedamage)
  50.     {
  51.         trace_ent.axhitme = 1;
  52.         SpawnBlood (org, '0 0 0', 20);
  53.         T_Damage (trace_ent, self, self, 20);
  54.     }
  55.     else
  56.     { // hit wall
  57.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  58.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  59.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  60.         WriteCoord (MSG_BROADCAST, org_x);
  61.         WriteCoord (MSG_BROADCAST, org_y);
  62.         WriteCoord (MSG_BROADCAST, org_z);
  63.     }
  64. };
  65.  
  66.  
  67. //============================================================================
  68.  
  69.  
  70. vector() wall_velocity =
  71. {
  72.     local vector  vel;
  73.     
  74.     vel = normalize (self.velocity);
  75.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  76.     vel = vel + 2*trace_plane_normal;
  77.     vel = vel * 200;
  78.     
  79.     return vel;
  80. };
  81.  
  82.  
  83. /*
  84. ================
  85. SpawnMeatSpray
  86. ================
  87. */
  88. void(vector org, vector vel) SpawnMeatSpray =
  89. {
  90.     local entity missile, mpuff;
  91.     local vector  org;
  92.  
  93.     missile = spawn ();
  94.     missile.owner = self;
  95.     missile.movetype = MOVETYPE_BOUNCE;
  96.     missile.solid = SOLID_NOT;
  97.  
  98.     makevectors (self.angles);
  99.  
  100.     missile.velocity = vel;
  101.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  102.  
  103.     missile.avelocity = '3000 1000 2000';
  104.     
  105. // set missile duration
  106.     missile.nextthink = time + 1;
  107.     missile.think = SUB_Remove;
  108.  
  109.     setmodel (missile, "progs/zom_gib.mdl");
  110.     setsize (missile, '0 0 0', '0 0 0');    
  111.     setorigin (missile, org);
  112. };
  113.  
  114. /*
  115. ================
  116. SpawnBlood
  117. ================
  118. */
  119. void(vector org, vector vel, float damage) SpawnBlood =
  120. {
  121.     particle (org, vel*0.1, 73, damage*2);
  122. };
  123.  
  124. /*
  125. ================
  126. spawn_touchblood
  127. ================
  128. */
  129. void(float damage) spawn_touchblood =
  130. {
  131.     local vector  vel;
  132.  
  133.     vel = wall_velocity () * 0.2;
  134.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  135. };
  136.  
  137.  
  138. /*
  139. ================
  140. SpawnChunk
  141. ================
  142. */
  143. void(vector org, vector vel) SpawnChunk =
  144. {
  145.     particle (org, vel*0.02, 0, 10);
  146. };
  147.  
  148. /*
  149. ==============================================================================
  150.  
  151. MULTI-DAMAGE
  152.  
  153. Collects multiple small damages into a single damage
  154.  
  155. ==============================================================================
  156. */
  157.  
  158. entity  multi_ent;
  159. float multi_damage;
  160.  
  161. void() ClearMultiDamage =
  162. {
  163.     multi_ent = world;
  164.     multi_damage = 0;
  165. };
  166.  
  167. void() ApplyMultiDamage =
  168. {
  169.     if (!multi_ent)
  170.         return;
  171.     T_Damage (multi_ent, self, self, multi_damage);
  172. };
  173.  
  174. void(entity hit, float damage) AddMultiDamage =
  175. {
  176.     if (!hit)
  177.         return;
  178.     
  179.     if (hit != multi_ent)
  180.     {
  181.         ApplyMultiDamage ();
  182.         multi_damage = damage;
  183.         multi_ent = hit;
  184.     }
  185.     else
  186.         multi_damage = multi_damage + damage;
  187. };
  188.  
  189. /*
  190. ==============================================================================
  191.  
  192. BULLETS
  193.  
  194. ==============================================================================
  195. */
  196.  
  197. /*
  198. ================
  199. TraceAttack
  200. ================
  201. */
  202. void(float damage, vector dir) TraceAttack =
  203. {
  204.     local vector  vel, org;
  205.     
  206.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  207.     vel = vel + 2*trace_plane_normal;
  208.     vel = vel * 200;
  209.  
  210.     org = trace_endpos - dir*4;
  211.  
  212.     if (trace_ent.takedamage)
  213.     {
  214.         SpawnBlood (org, vel*0.2, damage);
  215.         AddMultiDamage (trace_ent, damage);
  216.     }
  217.     else
  218.     {
  219.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  220.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  221.         WriteCoord (MSG_BROADCAST, org_x);
  222.         WriteCoord (MSG_BROADCAST, org_y);
  223.         WriteCoord (MSG_BROADCAST, org_z);
  224.     }
  225. };
  226.  
  227. /*
  228. ================
  229. FireBullets
  230.  
  231. Used by shotgun, super shotgun, and enemy soldier firing
  232. Go to the trouble of combining multiple pellets into a single damage call.
  233. ================
  234. */
  235. void(float shotcount, vector dir, vector spread) FireBullets =
  236. {
  237.     local vector direction;
  238.     local vector  src;
  239.     
  240.     makevectors(self.v_angle);
  241.  
  242.     src = self.origin + v_forward*10;
  243.     src_z = self.absmin_z + self.size_z * 0.7;
  244.  
  245.     ClearMultiDamage ();
  246.     while (shotcount > 0)
  247.     {
  248.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  249.  
  250.         traceline (src, src + direction*2048, FALSE, self);
  251.         if (trace_fraction != 1.0)
  252.             TraceAttack (4, direction);
  253.  
  254.         shotcount = shotcount - 1;
  255.     }
  256.     ApplyMultiDamage ();
  257. };
  258.  
  259. /*
  260. ================
  261. W_FireShotgun
  262. ================
  263. */
  264. void() W_FireShotgun =
  265. {
  266.     local vector dir;
  267.  
  268.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM); 
  269.  
  270.     self.punchangle_x = -2;
  271.     
  272.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  273.     dir = aim (self, 100000);
  274.     FireBullets (6, dir, '0.04 0.04 0');
  275. };
  276.  
  277.  
  278. /*
  279. ================
  280. W_FireSuperShotgun
  281. ================
  282. */
  283. void() W_FireSuperShotgun =
  284. {
  285.     local vector dir;
  286.  
  287.     if (self.currentammo == 1)
  288.     {
  289.         W_FireShotgun ();
  290.         return;
  291.     }
  292.         
  293.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM); 
  294.  
  295.     self.punchangle_x = -4;
  296.     
  297.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  298.     dir = aim (self, 100000);
  299.     FireBullets (14, dir, '0.14 0.08 0');
  300. };
  301.  
  302.  
  303. /*
  304. ==============================================================================
  305.  
  306. ROCKETS
  307.  
  308. ==============================================================================
  309. */
  310.  
  311. void()  s_explode1  = [0,   s_explode2] {};
  312. void()  s_explode2  = [1,   s_explode3] {};
  313. void()  s_explode3  = [2,   s_explode4] {};
  314. void()  s_explode4  = [3,   s_explode5] {};
  315. void()  s_explode5  = [4,   s_explode6] {};
  316. void()  s_explode6  = [5,   SUB_Remove] {};
  317.  
  318. void() BecomeExplosion =
  319. {
  320.     self.movetype = MOVETYPE_NONE;
  321.     self.velocity = '0 0 0';
  322.     self.touch = SUB_Null;
  323.     setmodel (self, "progs/s_explod.spr");
  324.     self.solid = SOLID_NOT;
  325.     s_explode1 ();
  326. };
  327.  
  328. void() T_MissileTouch =
  329. {
  330.     local float damg;
  331.  
  332.     if (other == self.owner)
  333.         return;   // don't explode on owner
  334.  
  335.     if (pointcontents(self.origin) == CONTENT_SKY)
  336.     {
  337.         remove(self);
  338.         return;
  339.     }
  340.  
  341.     damg = 100 + random()*20;
  342.     
  343.     if (other.health)
  344.     {
  345.         if (other.classname == "monster_shambler")
  346.             damg = damg * 0.5;  // mostly immune
  347.         T_Damage (other, self, self.owner, damg );
  348.     }
  349.  
  350.     // don't do radius damage to the other, because all the damage
  351.     // was done in the impact
  352.     T_RadiusDamage (self, self.owner, 120, other);
  353.  
  354. //  sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  355.     self.origin = self.origin - 8*normalize(self.velocity);
  356.  
  357.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  358.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  359.     WriteCoord (MSG_BROADCAST, self.origin_x);
  360.     WriteCoord (MSG_BROADCAST, self.origin_y);
  361.     WriteCoord (MSG_BROADCAST, self.origin_z);
  362.  
  363.     BecomeExplosion ();
  364. };
  365.  
  366.  
  367.  
  368. /*
  369. ================
  370. W_FireRocket
  371. ================
  372. */
  373. void() W_FireRocket =
  374. {
  375.     local entity missile, mpuff;
  376.     
  377.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  378.     
  379.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  380.  
  381.     self.punchangle_x = -2;
  382.  
  383.     missile = spawn ();
  384.     missile.owner = self;
  385.     missile.movetype = MOVETYPE_FLYMISSILE;
  386.     missile.solid = SOLID_BBOX;
  387.         
  388. // set missile speed  
  389.  
  390.     makevectors (self.v_angle);
  391.     missile.velocity = aim(self, 1000);
  392.     missile.velocity = missile.velocity * 1000;
  393.     missile.angles = vectoangles(missile.velocity);
  394.     
  395.     missile.touch = T_MissileTouch;
  396.     
  397. // set missile duration
  398.     missile.nextthink = time + 5;
  399.     missile.think = SUB_Remove;
  400.  
  401.     setmodel (missile, "progs/missile.mdl");
  402.     setsize (missile, '0 0 0', '0 0 0');    
  403.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  404. };
  405.  
  406. /*
  407. ===============================================================================
  408.  
  409. LIGHTNING
  410.  
  411. ===============================================================================
  412. */
  413.  
  414. /*
  415. =================
  416. LightningDamage
  417. =================
  418. */
  419. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  420. {
  421.     local entity    e1, e2;
  422.     local vector    f;
  423.     
  424.     f = p2 - p1;
  425.     normalize (f);
  426.     f_x = 0 - f_y;
  427.     f_y = f_x;
  428.     f_z = 0;
  429.     f = f*16;
  430.  
  431.     e1 = e2 = world;
  432.  
  433.     traceline (p1, p2, FALSE, self);
  434.     if (trace_ent.takedamage)
  435.     {
  436.         particle (trace_endpos, '0 0 100', 225, damage*4);
  437.         T_Damage (trace_ent, from, from, damage);
  438.         if (self.classname == "player")
  439.         {
  440.             if (other.classname == "player")
  441.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  442.         }
  443.     }
  444.     e1 = trace_ent;
  445.  
  446.     traceline (p1 + f, p2 + f, FALSE, self);
  447.     if (trace_ent != e1 && trace_ent.takedamage)
  448.     {
  449.         particle (trace_endpos, '0 0 100', 225, damage*4);
  450.         T_Damage (trace_ent, from, from, damage);
  451.     }
  452.     e2 = trace_ent;
  453.  
  454.     traceline (p1 - f, p2 - f, FALSE, self);
  455.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  456.     {
  457.         particle (trace_endpos, '0 0 100', 225, damage*4);
  458.         T_Damage (trace_ent, from, from, damage);
  459.     }
  460. };
  461.  
  462.  
  463. void() W_FireLightning =
  464. {
  465.     local vector    org;
  466.  
  467.     if (self.ammo_cells < 1)
  468.     {
  469.         self.weapon = W_BestWeapon ();
  470.         W_SetCurrentAmmo ();
  471.         return;
  472.     }
  473.  
  474. // explode if under water
  475.     if (self.waterlevel > 1)
  476.     {
  477.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  478.         self.ammo_cells = 0;
  479.         W_SetCurrentAmmo ();
  480.         return;
  481.     }
  482.  
  483.     if (self.t_width < time)
  484.     {
  485.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  486.         self.t_width = time + 0.6;
  487.     }
  488.     self.punchangle_x = -2;
  489.  
  490.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  491.  
  492.     org = self.origin + '0 0 16';
  493.     
  494.     traceline (org, org + v_forward*600, TRUE, self);
  495.  
  496.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  497.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  498.     WriteEntity (MSG_BROADCAST, self);
  499.     WriteCoord (MSG_BROADCAST, org_x);
  500.     WriteCoord (MSG_BROADCAST, org_y);
  501.     WriteCoord (MSG_BROADCAST, org_z);
  502.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  503.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  504.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  505.  
  506.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  507. };
  508.  
  509.  
  510. //=============================================================================
  511.  
  512. void() GrenadeExplode =
  513. {
  514.     T_RadiusDamage (self, self.owner, 120, world);
  515.  
  516.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  517.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  518.     WriteCoord (MSG_BROADCAST, self.origin_x);
  519.     WriteCoord (MSG_BROADCAST, self.origin_y);
  520.     WriteCoord (MSG_BROADCAST, self.origin_z);
  521.  
  522.     BecomeExplosion ();
  523. };
  524.  
  525. void() GrenadeTouch =
  526. {
  527.     if (other == self.owner)
  528.         return;   // don't explode on owner
  529.     if (other.takedamage == DAMAGE_AIM)
  530.     {
  531.         GrenadeExplode();
  532.         return;
  533.     }
  534.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);  // bounce sound
  535.     if (self.velocity == '0 0 0')
  536.         self.avelocity = '0 0 0';
  537. };
  538.  
  539. /*
  540. ================
  541. W_FireGrenade
  542. ================
  543. */
  544. void() W_FireGrenade =
  545. {
  546.     local entity missile, mpuff;
  547.     
  548.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  549.     
  550.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  551.  
  552.     self.punchangle_x = -2;
  553.  
  554.     missile = spawn ();
  555.     missile.owner = self;
  556.     missile.movetype = MOVETYPE_BOUNCE;
  557.     missile.solid = SOLID_BBOX;
  558.     missile.classname = "grenade";
  559.         
  560. // set missile speed  
  561.  
  562.     makevectors (self.v_angle);
  563.  
  564.     if (self.v_angle_x)
  565.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  566.     else
  567.     {
  568.         missile.velocity = aim(self, 10000);
  569.         missile.velocity = missile.velocity * 600;
  570.         missile.velocity_z = 200;
  571.     }
  572.  
  573.     missile.avelocity = '300 300 300';
  574.  
  575.     missile.angles = vectoangles(missile.velocity);
  576.     
  577.     missile.touch = GrenadeTouch;
  578.     
  579. // set missile duration
  580.     missile.nextthink = time + 2.5;
  581.     missile.think = GrenadeExplode;
  582.  
  583.     setmodel (missile, "progs/grenade.mdl");
  584.     setsize (missile, '0 0 0', '0 0 0');    
  585.     setorigin (missile, self.origin);
  586. };
  587.  
  588. //=============================================================================
  589.  
  590. void() spike_touch;
  591. void() superspike_touch;
  592.  
  593.  
  594. /*
  595. ===============
  596. launch_spike
  597.  
  598. Used for both the player and the ogre
  599. ===============
  600. */
  601. void(vector org, vector dir) launch_spike =
  602. {
  603.     newmis = spawn ();
  604.     newmis.owner = self;
  605.     newmis.movetype = MOVETYPE_FLYMISSILE;
  606.     newmis.solid = SOLID_BBOX;
  607.  
  608.     newmis.angles = vectoangles(dir);
  609.     
  610.     newmis.touch = spike_touch;
  611.     newmis.classname = "spike";
  612.     newmis.think = SUB_Remove;
  613.     newmis.nextthink = time + 6;
  614.     setmodel (newmis, "progs/spike.mdl");
  615.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);   
  616.     setorigin (newmis, org);
  617.     
  618.     newmis.velocity = dir * 1000;
  619. };
  620.  
  621. void() W_FireSuperSpikes =
  622. {
  623.     local vector  dir;
  624.     local entity  old;
  625.     
  626.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  627.     self.attack_finished = time + 0.2;
  628.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  629.     dir = aim (self, 1000);
  630.     launch_spike (self.origin + '0 0 16', dir);
  631.     newmis.touch = superspike_touch;
  632.     setmodel (newmis, "progs/s_spike.mdl");
  633.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);   
  634.     self.punchangle_x = -2;
  635. };
  636.  
  637. void(float ox) W_FireSpikes =
  638. {
  639.     local vector  dir;
  640.     local entity  old;
  641.     
  642.     makevectors (self.v_angle);
  643.     
  644.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  645.     {
  646.         W_FireSuperSpikes ();
  647.         return;
  648.     }
  649.  
  650.     if (self.ammo_nails < 1)
  651.     {
  652.         self.weapon = W_BestWeapon ();
  653.         W_SetCurrentAmmo ();
  654.         return;
  655.     }
  656.  
  657.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  658.     self.attack_finished = time + 0.2;
  659.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  660.     dir = aim (self, 1000);
  661.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  662.  
  663.     self.punchangle_x = -2;
  664. };
  665.  
  666.  
  667.  
  668. .float hit_z;
  669. void() spike_touch =
  670. {
  671. local float rand;
  672.     if (other == self.owner)
  673.         return;
  674.  
  675.     if (other.solid == SOLID_TRIGGER)
  676.         return; // trigger field, do nothing
  677.  
  678.     if (pointcontents(self.origin) == CONTENT_SKY)
  679.     {
  680.         remove(self);
  681.         return;
  682.     }
  683.     
  684. // hit something that bleeds
  685.     if (other.takedamage)
  686.     {
  687.         spawn_touchblood (9);
  688.         T_Damage (other, self, self.owner, 9);
  689.     }
  690.     else
  691.     {
  692.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  693.         
  694.         if (self.classname == "wizspike")
  695.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  696.         else if (self.classname == "knightspike")
  697.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  698.         else
  699.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  700.         WriteCoord (MSG_BROADCAST, self.origin_x);
  701.         WriteCoord (MSG_BROADCAST, self.origin_y);
  702.         WriteCoord (MSG_BROADCAST, self.origin_z);
  703.     }
  704.  
  705.     remove(self);
  706.  
  707. };
  708.  
  709. void() superspike_touch =
  710. {
  711. local float rand;
  712.     if (other == self.owner)
  713.         return;
  714.  
  715.     if (other.solid == SOLID_TRIGGER)
  716.         return; // trigger field, do nothing
  717.  
  718.     if (pointcontents(self.origin) == CONTENT_SKY)
  719.     {
  720.         remove(self);
  721.         return;
  722.     }
  723.     
  724. // hit something that bleeds
  725.     if (other.takedamage)
  726.     {
  727.         spawn_touchblood (18);
  728.         T_Damage (other, self, self.owner, 18);
  729.     }
  730.     else
  731.     {
  732.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  733.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  734.         WriteCoord (MSG_BROADCAST, self.origin_x);
  735.         WriteCoord (MSG_BROADCAST, self.origin_y);
  736.         WriteCoord (MSG_BROADCAST, self.origin_z);
  737.     }
  738.  
  739.     remove(self);
  740.  
  741. };
  742.  
  743.  
  744. /*
  745. ===============================================================================
  746.  
  747. PLAYER WEAPON USE
  748.  
  749. ===============================================================================
  750. */
  751.  
  752. void() W_SetCurrentAmmo =
  753. {
  754.     local float tmp;
  755.     player_run ();    // get out of any weapon firing states
  756.  
  757.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  758.     if (self.ef&EXTRA_1) 
  759.     {
  760.         if (self.weapon == WP_CLUSTER)
  761.         {
  762.             self.currentammo = floor(self.ammo_rockets/7);
  763.             self.weaponmodel = "progs/v_rock.mdl";
  764.             self.weaponframe = 0;
  765.             self.items = self.items | IT_ROCKETS;
  766.         }
  767.     }
  768.     else
  769.     {
  770.         if (self.weapon == IT_AXE)
  771.         {
  772.             self.currentammo = 0;
  773.             self.weaponmodel = "progs/v_axe.mdl";
  774.             self.weaponframe = 0;
  775.         }
  776.         else if (self.weapon == IT_SHOTGUN)
  777.         {
  778.             self.currentammo = self.ammo_shells;
  779.             self.weaponmodel = "progs/v_shot.mdl";
  780.             self.weaponframe = 0;
  781.             self.items = self.items | IT_SHELLS;
  782.         }
  783.         else if (self.weapon == IT_SUPER_SHOTGUN)
  784.         {
  785.             self.currentammo = self.ammo_shells;
  786.             self.weaponmodel = "progs/v_shot2.mdl";
  787.             self.weaponframe = 0;
  788.             self.items = self.items | IT_SHELLS;
  789.         }
  790.         else if (self.weapon == IT_NAILGUN)
  791.         {
  792.             self.currentammo = self.ammo_nails;
  793.             self.weaponmodel = "progs/v_nail.mdl";
  794.             self.weaponframe = 0;
  795.             self.items = self.items | IT_NAILS;
  796.         }
  797.         else if (self.weapon == IT_SUPER_NAILGUN)
  798.         {
  799.             self.currentammo = self.ammo_nails;
  800.             self.weaponmodel = "progs/v_nail2.mdl";
  801.             self.weaponframe = 0;
  802.             self.items = self.items | IT_NAILS;
  803.         }
  804.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  805.         {
  806.             self.currentammo = self.ammo_rockets;
  807.             self.weaponmodel = "progs/v_rock.mdl";
  808.             self.weaponframe = 0;
  809.             self.items = self.items | IT_ROCKETS;
  810.         }
  811.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  812.         {
  813.             self.currentammo = self.ammo_rockets;
  814.             self.weaponmodel = "progs/v_rock2.mdl";
  815.             self.weaponframe = 0;
  816.             self.items = self.items | IT_ROCKETS;
  817.         }
  818.         else if (self.weapon == IT_LIGHTNING)
  819.         {
  820.             self.currentammo = self.ammo_cells;
  821.             self.weaponmodel = "progs/v_light.mdl";
  822.             self.weaponframe = 0;
  823.             self.items = self.items | IT_CELLS;
  824.         }
  825.         else
  826.         {
  827.             self.currentammo = 0;
  828.             self.weaponmodel = "";
  829.             self.weaponframe = 0;
  830.         }
  831.     }
  832. };
  833.  
  834. float() W_BestWeapon =
  835. {
  836.     local float it;
  837.     
  838.     it = self.items;
  839.  
  840.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  841.         return IT_LIGHTNING;
  842.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  843.         return IT_SUPER_NAILGUN;
  844.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  845.         return IT_SUPER_SHOTGUN;
  846.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  847.         return IT_NAILGUN;
  848.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  849.         return IT_SHOTGUN;
  850.         
  851. /*
  852.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  853.         return IT_ROCKET_LAUNCHER;
  854.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  855.         return IT_GRENADE_LAUNCHER;
  856.  
  857. */
  858.  
  859.     return IT_AXE;
  860. };
  861.  
  862. float() W_CheckNoAmmo =
  863. {
  864.     if (self.currentammo > 0)
  865.         return TRUE;
  866.  
  867.     if (self.weapon == IT_AXE)
  868.         return TRUE;
  869.  
  870.     self.weapon = W_BestWeapon ();
  871.  
  872.     W_SetCurrentAmmo ();
  873.     
  874. // drop the weapon down
  875.     return FALSE;
  876. };
  877.  
  878. /*
  879. ============
  880. W_Attack
  881.  
  882. An attack impulse can be triggered now
  883. ============
  884. */
  885. void()  player_axe1;
  886. void()  player_axeb1;
  887. void()  player_axec1;
  888. void()  player_axed1;
  889. void()  player_shot1;
  890. void()  player_nail1;
  891. void()  player_light1;
  892. void()  player_rocket1;
  893.  
  894. void() W_Attack =
  895. {
  896.     local float r;
  897.  
  898.     if (!W_CheckNoAmmo ())
  899.         return;
  900.  
  901.     makevectors (self.v_angle);     // calculate forward angle for velocity
  902.     self.show_hostile = time + 1; // wake monsters up
  903.     
  904.     if (self.ef&EXTRA_1) 
  905.     {
  906.         if (self.weapon == WP_CLUSTER)
  907.         {
  908.             player_rocket1();
  909.             W_FireCluster();
  910.             self.attack_finished = time + 0.6;
  911.         }
  912.     }
  913.     else
  914.     {
  915.         if (self.weapon == IT_AXE)
  916.         {
  917.             sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  918.             r = random();
  919.             if (r < 0.25)
  920.                 player_axe1 ();
  921.             else if (r<0.5)
  922.                 player_axeb1 ();
  923.             else if (r<0.75)
  924.                 player_axec1 ();
  925.             else
  926.                 player_axed1 ();
  927.             self.attack_finished = time + 0.5;
  928.         }
  929.         else if (self.weapon == IT_SHOTGUN)
  930.         {
  931.             player_shot1 ();
  932.             W_FireShotgun ();
  933.             self.attack_finished = time + 0.5;
  934.         }
  935.         else if (self.weapon == IT_SUPER_SHOTGUN)
  936.         {
  937.             player_shot1 ();
  938.             W_FireSuperShotgun ();
  939.             self.attack_finished = time + 0.7;
  940.         }
  941.         else if (self.weapon == IT_NAILGUN)
  942.         {
  943.             player_nail1 ();
  944.         }
  945.         else if (self.weapon == IT_SUPER_NAILGUN)
  946.         {
  947.             player_nail1 ();
  948.         }
  949.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  950.         {
  951.             player_rocket1();
  952.             W_FireGrenade();
  953.             self.attack_finished = time + 0.6;
  954.         }
  955.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  956.         {
  957.             player_rocket1();
  958.             W_FireRocket();
  959.             self.attack_finished = time + 0.8;
  960.         }
  961.         else if (self.weapon == IT_LIGHTNING)
  962.         {
  963.             player_light1();
  964.             self.attack_finished = time + 0.1;
  965.             sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  966.         }
  967.     }
  968. };  
  969.  
  970. /*
  971. ============
  972. W_ChangeWeapon
  973.  
  974. ============
  975. */
  976. void() W_ChangeWeapon =
  977. {
  978.     local float it, am, fl, extra;
  979.     
  980.     it = self.items;
  981.     am = 0;
  982.  
  983.     if (self.impulse == 1)
  984.     {
  985.         fl = IT_AXE;
  986.         extra=0;    
  987.     }
  988.     else if (self.impulse == 2)
  989.     {
  990.         fl = IT_SHOTGUN;
  991.         extra=0;    
  992.         if (self.ammo_shells < 1)
  993.             am = 1;
  994.     }
  995.     else if (self.impulse == 3)
  996.     {
  997.         fl = IT_SUPER_SHOTGUN;
  998.         extra=0;    
  999.         if (self.ammo_shells < 2)
  1000.             am = 1;
  1001.     }   
  1002.     else if (self.impulse == 4)
  1003.     {
  1004.         fl = IT_NAILGUN;
  1005.         extra=0;    
  1006.         if (self.ammo_nails < 1)
  1007.             am = 1;
  1008.     }
  1009.     else if (self.impulse == 5)
  1010.     {
  1011.         fl = IT_SUPER_NAILGUN;
  1012.         extra=0;    
  1013.         if (self.ammo_nails < 2)
  1014.             am = 1;
  1015.     }
  1016.     else if (self.impulse == 6)
  1017.     {
  1018.         fl = IT_GRENADE_LAUNCHER;
  1019.         extra=0;    
  1020.         if (self.ammo_rockets < 1)
  1021.             am = 1;
  1022.     }
  1023.     else if (self.impulse == 7)
  1024.     {
  1025.         fl = IT_ROCKET_LAUNCHER;
  1026.         extra=0;    
  1027.         if (self.ammo_rockets < 1)
  1028.             am = 1;
  1029.     }
  1030.     else if (self.impulse == 8)
  1031.     {
  1032.         fl = IT_LIGHTNING;
  1033.         extra=0;    
  1034.         if (self.ammo_cells < 1)
  1035.             am = 1;
  1036.     }
  1037.     else if (self.impulse == IM_CLUSTER)
  1038.     {
  1039.         fl = WP_CLUSTER;
  1040.         extra = EXTRA_1;
  1041.         centerprint(self,"Cluster Bombs selected\n");   
  1042.         if (self.ammo_rockets < 7) 
  1043.             am=1;
  1044.     }
  1045.     self.impulse = 0;
  1046.     
  1047.     if (extra==0)
  1048.     {
  1049.         if (!(self.items & fl))
  1050.         { // don't have the weapon or the ammo
  1051.             sprint (self, "no weapon.\n");
  1052.             return;
  1053.         }
  1054.     }
  1055.     else
  1056.     {
  1057.         if (!(self.weapons1 &fl))
  1058.         {
  1059.             sprint(self,"no weapon.\n");
  1060.             return;
  1061.         }
  1062.     }
  1063.     if (am)
  1064.     { // don't have the ammo
  1065.         sprint (self, "not enough ammo.\n");
  1066.         return;
  1067.     }
  1068.  
  1069. //
  1070. // set weapon, set ammo
  1071. //
  1072.     self.weapon = fl;   
  1073.     self.ef = extra;
  1074.     W_SetCurrentAmmo ();
  1075. };
  1076.  
  1077. /*
  1078. ============
  1079. CheatCommand
  1080. ============
  1081. */
  1082. void() CheatCommand =
  1083. {
  1084.     if (deathmatch || coop)
  1085.         return;
  1086.  
  1087.     self.ammo_rockets = 100;
  1088.     self.ammo_nails = 200;
  1089.     self.ammo_shells = 100;
  1090.     self.items = self.items | 
  1091.         IT_AXE |
  1092.         IT_SHOTGUN |
  1093.         IT_SUPER_SHOTGUN |
  1094.         IT_NAILGUN |
  1095.         IT_SUPER_NAILGUN |
  1096.         IT_GRENADE_LAUNCHER |
  1097.         IT_ROCKET_LAUNCHER |
  1098.         IT_KEY1 | IT_KEY2;
  1099.     self.ammo_cells = 200;
  1100.     self.items = self.items | IT_LIGHTNING;
  1101.     self.weapons1 = self.weapons1 |
  1102.         WP_CLUSTER;
  1103.     self.weapon = IT_ROCKET_LAUNCHER;
  1104.     self.ef = 0;
  1105.     self.impulse = 0;
  1106.     W_SetCurrentAmmo ();
  1107. };
  1108.  
  1109. /*
  1110. ============
  1111. CycleWeaponCommand
  1112.  
  1113. Go to the next weapon with ammo
  1114. ============
  1115. */
  1116. void() CycleWeaponCommand =
  1117. {
  1118.     local float it, am;
  1119.     
  1120.     it = self.items;
  1121.     self.impulse = 0;
  1122.     
  1123.     while (1)
  1124.     {
  1125.         am = 0;
  1126.  
  1127.         if (self.weapon == IT_LIGHTNING)
  1128.         {
  1129.             self.weapon = IT_AXE;
  1130.             self.ef = 0;            
  1131.         }
  1132.         else if (self.weapon == IT_AXE)
  1133.         {
  1134.             self.weapon = IT_SHOTGUN;
  1135.             self.ef = 0;            
  1136.             if (self.ammo_shells < 1)
  1137.                 am = 1;
  1138.         }
  1139.         else if (self.weapon == IT_SHOTGUN)
  1140.         {
  1141.             self.weapon = IT_SUPER_SHOTGUN;
  1142.             self.ef = 0;            
  1143.             if (self.ammo_shells < 2)
  1144.                 am = 1;
  1145.         }   
  1146.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1147.         {
  1148.             self.weapon = IT_NAILGUN;
  1149.             self.ef = 0;            
  1150.             if (self.ammo_nails < 1)
  1151.                 am = 1;
  1152.         }
  1153.         else if (self.weapon == IT_NAILGUN)
  1154.         {
  1155.             self.weapon = IT_SUPER_NAILGUN;
  1156.             self.ef = 0;            
  1157.             if (self.ammo_nails < 2)
  1158.                 am = 1;
  1159.         }
  1160.         else if (self.weapon == IT_SUPER_NAILGUN)
  1161.         {
  1162.             self.weapon = IT_GRENADE_LAUNCHER;
  1163.             self.ef = 0;            
  1164.             if (self.ammo_rockets < 1)
  1165.                 am = 1;
  1166.         }
  1167.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1168.         {
  1169.             self.weapon = WP_CLUSTER;
  1170.             self.ef = EXTRA_1;
  1171.             if (self.ammo_rockets < 7)
  1172.                 am = 1;
  1173.         }
  1174.         else if (self.weapon == WP_CLUSTER)
  1175.         {
  1176.             self.weapon = IT_ROCKET_LAUNCHER;
  1177.             self.ef = 0;            
  1178.             if (self.ammo_rockets < 1)
  1179.                 am=1;
  1180.         }
  1181.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1182.         {
  1183.             self.weapon = IT_LIGHTNING;
  1184.             self.ef = 0;      
  1185.             if (self.ammo_cells < 1)
  1186.                 am = 1;
  1187.         }
  1188.         
  1189.         if (self.ef==EXTRA_1)
  1190.         {
  1191.             if ((self.weapons1 & self.weapon) && am ==0)
  1192.             {
  1193.                 W_SetCurrentAmmo();
  1194.                 return;
  1195.             }
  1196.         }
  1197.         else if ( (self.items & self.weapon) && am == 0)
  1198.         {
  1199.             W_SetCurrentAmmo ();
  1200.             return;
  1201.         }
  1202.     }
  1203.  
  1204. };
  1205.  
  1206. /*
  1207. ============
  1208. ServerflagsCommand
  1209.  
  1210. Just for development
  1211. ============
  1212. */
  1213. void() ServerflagsCommand =
  1214. {
  1215.     serverflags = serverflags * 2 + 1;
  1216. };
  1217.  
  1218. void() QuadCheat =
  1219. {
  1220.     if (deathmatch || coop)
  1221.         return;
  1222.     self.super_time = 1;
  1223.     self.super_damage_finished = time + 30;
  1224.     self.items = self.items | IT_QUAD;
  1225.     dprint ("quad cheat\n");
  1226. };
  1227.  
  1228. /*
  1229. ============
  1230. ImpulseCommands
  1231.  
  1232. ============
  1233. */
  1234. void() ImpulseCommands =
  1235. {
  1236.     if (self.impulse >= 1 && self.impulse <= 8)
  1237.         W_ChangeWeapon ();
  1238.  
  1239.     if (self.impulse == 9)
  1240.         CheatCommand ();
  1241.     if (self.impulse == 10)
  1242.         CycleWeaponCommand ();
  1243.     if (self.impulse == 11)
  1244.         ServerflagsCommand ();
  1245.     if (self.impulse == IM_CLUSTER)
  1246.         W_ChangeWeapon();
  1247.  
  1248.     if (self.impulse == 255)
  1249.         QuadCheat ();
  1250.         
  1251.     self.impulse = 0;
  1252. };
  1253.  
  1254. /*
  1255. ============
  1256. W_WeaponFrame
  1257.  
  1258. Called every frame so impulse events can be handled as well as possible
  1259. ============
  1260. */
  1261. void() W_WeaponFrame =
  1262. {
  1263.     if (time < self.attack_finished)
  1264.         return;
  1265.  
  1266.     ImpulseCommands ();
  1267.     
  1268. // check for attack
  1269.     if (self.button0)
  1270.     {
  1271.         SuperDamageSound ();
  1272.         W_Attack ();
  1273.     }
  1274. };
  1275.  
  1276. /*
  1277. ========
  1278. SuperDamageSound
  1279.  
  1280. Plays sound if needed
  1281. ========
  1282. */
  1283. void() SuperDamageSound =
  1284. {
  1285.     if (self.super_damage_finished > time)
  1286.     {
  1287.         if (self.super_sound < time)
  1288.         {
  1289.             self.super_sound = time + 1;
  1290.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1291.         }
  1292.     }
  1293.     return;
  1294. };
  1295.  
  1296.  
  1297.